<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 

class MY_Controller extends CI_Controller{


	public $user_session = array();
	public $page_size =10;
	public function __construct()
	{
		parent::__construct();

		$this->user_session = $this->session->all_userdata();
		//表单验证
		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<span class="warning"><label class="error">', '</label><span>');		
	}

	public function check_user()
	{
		if($this->user_session['uid'] <=0 || $this->user_session['roleid']<0)
		{
			redirect('c=user&m=login', 'refresh');
		}
	}
	//获取管理员session
	public function get_user_session()
	{
		return $this->user_session;
	}
	
	//显示操作信息
	public function show_message($message,$url_forward,$second=10)
	{
		$message.="<script>setTimeout(\"window.location.href ='$url_forward';\", ".($second*1000).");</script>";
		$this->load->template('show_message',array('message'=>$message,'url_forward'=>$url_forward,'second'=>$second));
	}

	//分页
	public function create_page_links($base_url,$total_rows,$page_size=10)
	{
		 //分页设置
		$this->load->library('pagination');

		$config['base_url'] =  $base_url;
		$config['total_rows'] = $total_rows;
		$config['per_page'] = $page_size; 

		$this->pagination->initialize($config); 
		$links=  $this->pagination->create_links();
		return $links;
	} 
}
 